home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ttedit / tt_edit.bas < prev    next >
BASIC Source File  |  1995-01-04  |  7KB  |  223 lines

  1. Option Explicit
  2.  
  3. ' This module contains routines and stuff specific to this app.
  4.  
  5. Global Const APP_VERSION_NUMBER = "1.0.0.0.0.0.0.0.1 Rev A"
  6. Global Const APP_TITLE = "TT Editor"
  7. Global Const APP_HELPFILE = "NOTEPAD.HLP"
  8. Global Const NEW_FILE_TITLE = "<Untitled>"
  9.  
  10.  
  11. Global Const BUTTON_OPEN = 0
  12. Global Const BUTTON_NEW = 1
  13. Global Const BUTTON_PRINT = 2
  14. Global Const BUTTON_CUT = 3
  15. Global Const BUTTON_COPY = 4
  16. Global Const BUTTON_PASTE = 5
  17. Global Const BUTTON_FIND = 6
  18. Global Const BUTTON_TOOLTIPS = 7
  19. Global Const BUTTON_HELP = 8
  20.  
  21. Global Const TOTAL_BUTTONS = 9
  22.  
  23. 'Declare an array for each type of Mulitple Instance forms
  24. Global Forms_frmTextEdit() As New frmTextEdit
  25.  
  26. ' Give each Class of Mulitple Instance form an identifying number
  27. ' Calling it "class" will really anoy your VC++ friends !!
  28.  
  29. Global Const CLASS_frmTextEdit = 1
  30.  
  31. Sub EditMenu (Enable As Integer)
  32.    MDI.mnu_File_Save.Enabled = Enable
  33.    MDI.mnu_File_SaveAs.Enabled = Enable
  34.    MDI.mnu_File_Print.Enabled = Enable
  35.    MDI.mnu_Edit_Copy.Enabled = Enable
  36.    MDI.mnu_Edit_Cut.Enabled = Enable
  37.    MDI.mnu_Edit_Delete.Enabled = Enable
  38.    MDI.mnu_Edit_Paste.Enabled = Enable
  39.    MDI.mnu_Edit_SelectAll.Enabled = Enable
  40.    MDI.mnu_Edit_TimeDate.Enabled = Enable
  41.    MDI.mnu_Edit_Undo.Enabled = Enable
  42.    MDI.mnu_Edit_WordWrap.Enabled = Enable
  43.    MDI.mnu_Search_Find.Enabled = Enable
  44.    MDI.mnu_Search_FindNext.Enabled = Enable
  45.    Call SynchButtons
  46. End Sub
  47.  
  48. Sub FindNextText (Search As String, Down As Integer, Compare As Integer)
  49.     Dim Temp$
  50.     Dim X As Integer
  51.     Dim Start As Integer
  52.     Dim C As Control
  53.     Set C = MDI.ActiveForm.ActiveControl
  54.     Start = C.SelStart + C.SelLength + 1
  55.     If Compare Then Compare = 0 Else Compare = 1
  56.     Temp$ = C
  57.     If Down Then
  58.       X = InStr(Start, Temp$, Search, Compare)
  59.     Else
  60.       Start = InStr(1, Temp$, Search, Compare)
  61.       X = Start
  62.       Do
  63.         Start = InStr(Start + 1, Temp$, Search, Compare)
  64.         If Start And Start < C.SelStart - 1 Then X = Start Else Exit Do
  65.       Loop
  66.     End If
  67.     If X Then
  68.       C.SelStart = X - 1
  69.       C.SelLength = Len(Search)
  70.     Else
  71.       X = MsgBox("Cannot find " & Chr(34) & Search & Chr(34), MB_ICONINFORMATION + MB_OK)
  72.     End If
  73. End Sub
  74.  
  75. Sub GetWindowPos (F As Form)
  76.    Dim lpFileName$, lpDefault%
  77.    Dim lpAppName$, lpKeyName$, X  As Integer
  78.    lpAppName$ = F.Caption
  79.    lpFileName$ = App.EXEName & ".ini"
  80.    
  81.    lpDefault% = Screen.Height * .1
  82.    lpKeyName$ = "Top"
  83.    X = GetPrivateProfileInt(lpAppName$, lpKeyName$, lpDefault%, lpFileName$)
  84.    If X Then F.Top = X Else F.Top = lpDefault%
  85.    
  86.    lpDefault% = Screen.Width * .1
  87.    lpKeyName$ = "Left"
  88.    X = GetPrivateProfileInt(lpAppName$, lpKeyName$, lpDefault%, lpFileName$)
  89.    If X Then F.Left = X Else F.Left = lpDefault%
  90.  
  91.    lpDefault% = Screen.Width * .8
  92.    lpKeyName$ = "Width"
  93.    X = GetPrivateProfileInt(lpAppName$, lpKeyName$, lpDefault%, lpFileName$)
  94.    If X Then F.Width = X Else F.Width = lpDefault%
  95.    
  96.    lpDefault% = Screen.Height * .8
  97.    lpKeyName$ = "Height"
  98.    X = GetPrivateProfileInt(lpAppName$, lpKeyName$, lpDefault%, lpFileName$)
  99.    If X Then F.Height = X Else F.Height = lpDefault%
  100.  
  101. End Sub
  102.  
  103. Sub Main ()
  104.    If App.PrevInstance Then
  105.        App.Title = "... duplicate instance."
  106.        AppActivate APP_TITLE
  107.        SendKeys "% R", True
  108.        End
  109.    End If
  110.    Screen.MousePointer = 11: DoEvents  ' Hourglass
  111.    App.HelpFile = APP_HELPFILE
  112.    Call Init_FormDetails
  113.    frmAbout.Show
  114.    frmAbout.Refresh
  115.    DoEvents
  116.    Call SetWindowPos(frmAbout.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
  117.    MDI.Show
  118.    Call DragAcceptFiles(MDI.hWnd, True)     'identify App to accept d/d messages
  119.    Unload frmAbout
  120.    If Len(Command$) Then
  121.       Dim Temp$
  122.       Temp$ = OpenFile(Command$)
  123.       If Len(Temp$) Then
  124.         Call NewFile
  125.         MDI.ActiveForm.Caption = UCase$(Command$)
  126.         MDI.ActiveForm.txtTextEdit = Temp$
  127.       End If
  128.    End If
  129.    Screen.MousePointer = 0
  130.    Call Main_Loop
  131. End Sub
  132.  
  133. Sub Main_Loop ()
  134.    Do While DoEvents()
  135.       If MDI.WindowState <> MINIMIZED Then
  136.          Call UpdateStatusBar(MDI.StatusBar)
  137.          Call TT_Test
  138.          Call UpdateEditMenu
  139.       End If
  140.       Call CheckDragDrop(CInt(MDI.hWnd))
  141.    Loop
  142. End Sub
  143.  
  144. Function OpenFile (FileName As String) As String
  145.    On Error Resume Next
  146.    Dim Handle As Integer
  147.    Dim X As Integer
  148.    ' Test to see whether the file is already open
  149.    For X = 0 To Forms.Count - 1
  150.       If Forms(X).Caption = FileName Then
  151.          Forms(X).SetFocus
  152.          Exit Function
  153.       End If
  154.    Next
  155.    ' Attempt to open the file if it isn't already
  156.    Handle = FreeFile
  157.    Open FileName For Binary As Handle
  158.    If LOF(Handle) > 60000 Then
  159.      Close Handle
  160.      X = MsgBox("File is too large. Launch Write instead ?", MB_ICONQUESTION + MB_OKCANCEL)
  161.      If X = IDOK Then
  162.         Handle = Shell("Write.exe " & FileName, 1)
  163.      End If
  164.    Else
  165.      OpenFile = Input$(LOF(Handle), Handle)
  166.      Close Handle
  167.    End If
  168. End Function
  169.  
  170. Sub SaveWindowPos (F As Form)
  171.    Dim lpFileName$, lpValue$
  172.    Dim lpAppName$, lpKeyName$
  173.    
  174.    lpAppName$ = F.Caption
  175.    lpFileName$ = App.EXEName & ".ini"
  176.    
  177.    lpKeyName$ = "Top"
  178.    lpValue$ = F.Top
  179.    If WritePrivateProfileString(lpAppName$, lpKeyName$, lpValue$, lpFileName$) Then
  180.    End If
  181.    lpKeyName$ = "Left"
  182.    lpValue$ = F.Left
  183.    If WritePrivateProfileString(lpAppName$, lpKeyName$, lpValue$, lpFileName$) Then
  184.    End If
  185.    lpKeyName$ = "Width"
  186.    lpValue$ = F.Width
  187.    If WritePrivateProfileString(lpAppName$, lpKeyName$, lpValue$, lpFileName$) Then
  188.    End If
  189.    lpKeyName$ = "Height"
  190.    lpValue$ = F.Height
  191.    If WritePrivateProfileString(lpAppName$, lpKeyName$, lpValue$, lpFileName$) Then
  192.    End If
  193.  
  194. End Sub
  195.  
  196. Sub UpdateEditMenu ()
  197.    Dim C As Control
  198.    If Not Screen.ActiveForm Is Forms(0) Then
  199.      Set C = Screen.ActiveControl
  200.      If Not C Is Nothing Then
  201.        MDI.mnu_Edit_Undo.Enabled = sendMessage(C.hWnd, EM_CANUNDO, 0, ByVal 0&)
  202.        MDI.mnu_Edit_Paste.Enabled = IsClipboardFormatAvailable(CF_TEXT) Or IsClipboardFormatAvailable(CF_OEMTEXT) Or IsClipboardFormatAvailable(CF_DSPTEXT)
  203.        MDI.mnu_Edit_Cut.Enabled = (sendMessage(C.hWnd, EM_GETSEL, 0, ByVal 0&) And &HFFFF&) - (sendMessage(C.hWnd, EM_GETSEL, 0, ByVal 0&) \ &H10000 And &HFFFF&)
  204.        MDI.mnu_Edit_Copy.Enabled = MDI.mnu_Edit_Cut.Enabled
  205.        MDI.mnu_Edit_Delete.Enabled = MDI.mnu_Edit_Cut.Enabled
  206.        Call SynchButtons
  207.      End If
  208.    End If
  209. End Sub
  210.  
  211. Sub WriteFile (FileName As String, FileData As String)
  212.    Dim X As Integer
  213.    Dim Handle As Integer
  214.    On Error Resume Next
  215.    Err = False
  216.    Handle = FreeFile
  217.    Open FileName For Output As Handle
  218.    Print #Handle, FileData
  219.    Close Handle
  220.    If Err Then X = MsgBox("An Error occured while saving.", MB_OK)
  221. End Sub
  222.  
  223.